package com.wyg.service;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.page.Page;
import com.wyg.dao.UserDao;
import com.wyg.pojo.User;

public class AllUserService {
	
	public HttpServletRequest request;
	public HttpServletResponse response;
	public UserDao ud = new UserDao();
	
	public AllUserService(HttpServletRequest request, HttpServletResponse response) {
		super();
		this.request = request;
		this.response = response;
	}
	
	public void queryAllUser(){
		
		String no = request.getParameter("pageNo");
		
		int pageSize = 10;
		int pageNo=1;
		
		if(no!=null && no!=""){
			pageNo=Integer.parseInt(no);
		}
		
		int totalCount = ud.getTotalCount();
		Page page = new Page(pageSize,pageNo,totalCount);
		List<User> list = ud.findPage(page);
		if(list!=null){
			System.out.println("fint all page");
			request.setAttribute("list", list);
			request.setAttribute("page", page);
			try {
				request.getRequestDispatcher("main/allUser.jsp").forward(request, response);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		
//		List list = ud.queryAllUser();
//		request.getSession().setAttribute("list", list);
//		try {
//			request.getRequestDispatcher("main/allUser.jsp").forward(request, response);
//		} catch (ServletException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
	}
	
	

}
